package de.hm.edu.config;

import java.io.IOException;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import de.hm.edu.c2dm.AuthenticationUtil;
import de.hm.edu.cep.EventEngine;
import de.hm.edu.simulation.Simulation1;

/**
 * Tomcat Server Context that defines task on during server start up and shut down
 * @author Peter Goldenbogen (Munich University of Applied Science)
 * @version 1.0 
 *
 */
public class Context implements ServletContextListener {
	
	    public void contextInitialized(ServletContextEvent event) {
	    	//instantiate cep engine
	    	EventEngine.initEE();
	    	
	    	//request c2dm server token
	    	try {
				AuthenticationUtil.setAuth_token(AuthenticationUtil.requestToken());
				System.out.println(AuthenticationUtil.getAuth_token());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    	
	    	//Start Order Simulation Thread
	    	Simulation1 sim= new Simulation1();
	    	sim.start();
	    }
	    public void contextDestroyed(ServletContextEvent event) {
	        // Do your thing during webapp's shutdown.
	    }
}



